#pragma once

struct PanelText
{
	PanelText(std::string t, std::string i) : m_text(t), m_info(i)
	{
	}
	std::string m_text;
	std::string m_info;
};

class Panel : public UIElement
{
	Texture* m_frameTex;
	Texture* m_closeIcon, *m_closeIconDown;
	Texture* m_circleIcon;
	Vertex3FCRHWT m_closeVertices[4];
	Vertex3FCRHWT m_frameVer[4];
	Vertex3FCRHWT m_iconVertices[4];
	CFont m_title;
	std::string m_szTitle;
	bool m_closeHovered;
	bool m_moveAble;
	bool m_fadedIn;
	bool m_fadeIn;
	ui32 m_fadeStart;
	Vertex2F m_moveLast;
	std::vector<PanelText> m_texts;
	i32 m_hoveredText;
	std::set<UIButton<Panel>*> m_buttons;
public:
	Panel(ui32 x, ui32 y, std::string szTitle = "");
	void Draw();
	void FadeIn();
	void FadeOut();
	void MouseActivity(bool left, Vertex2F pos, bool up);
	void OnMouseMove(ui32 x, ui32 y, bool lDown, bool rDown);
	void SetString(ui32 pos, std::string newString)
	{
		if(pos >= m_texts.size())
			return;
		m_texts[pos].m_text = newString;
	}

	ui32 InsertString(std::string text, std::string info)
	{
		m_texts.push_back(PanelText(text, info));
		return m_texts.size() - 1;
	}

	template<typename T>
	UIButton<T>* AddButton(T* instance, ui32 x, ui32 y, ui32 w, std::string szText, void (T::*proc)(UIButton<T>*))
	{
		UIButton<T>* pButton = new UIButton<T>(instance, Vertex2F(m_position.x + x, m_position.y + y), Vertex2F((float)w, 25), szText);
		pButton->SetOnClick(proc);
		m_buttons.insert((UIButton<Dialog>*)pButton);
		return pButton;
	}
};